package ex.datastream.functions.dataStream;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 将N个相同类型的 dataStream 合并成一个新的 dataStream
 */
public class UnionTest {

    public static void main(String[] args) throws Exception {
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStream<Tuple2<String, Integer>> dataStream1 = env.
                fromElements(Tuple2.of("a", 3), Tuple2.of("d", 4), Tuple2.of("c", 2), Tuple2.of("c", 5), Tuple2.of("a", 5));
        DataStream<Tuple2<String, Integer>> dataStream2 = env.
                fromElements(Tuple2.of("d", 1), Tuple2.of("s", 2), Tuple2.of("a", 4), Tuple2.of("e", 5), Tuple2.of("a", 6));
        DataStream<Tuple2<String, Integer>> dataStream3 = env.
                fromElements(Tuple2.of("d", 11), Tuple2.of("s", 12), Tuple2.of("a", 14), Tuple2.of("e", 1), Tuple2.of("a", 16));
        DataStream union = dataStream1.union(dataStream2, dataStream3);
        union.print();
        env.execute();
    }
}
